package com.egao.api.controller.orderB;


import com.egao.api.base.BaseApiController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageResult2;
import com.egao.common.system.entity.OperRecord;
import com.egao.common.system.entity.User;
import com.egao.common.system.service.OperRecordService;
import com.egao.orderB.entity.Driver;
import com.egao.orderB.entity.Customer;
import com.egao.orderB.entity.Driver;
import com.egao.orderB.service.AddressService;
import com.egao.orderB.service.DriverService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

//import com.egao.orderB.entity.Bill;
//import com.egao.orderB.service.BillService;

/**
 * api登录相关接口
 * Created by wangfan on 2019-05-29 下午 3:43.
 * http://localhost/swagger-ui.html
 * https://francjc.com:4332/swagger-ui.html
 */
@RequestMapping("/api/driver")
@RestController
@Api(value = "司机管理",tags = {"司机管理"})
public class ApiDriveController extends BaseApiController {

    @Autowired
    private OperRecordService operRecordService;
    @Autowired
    private DriverService driverService;

    /**
     * 添加运费报价
     */
    @PostMapping("/list")
    @ApiOperation(value = "司机列表",notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            "name:司机姓名\n" +
            "whiteCard:白卡号\n" +
            "state: 状态:未审核/已审核\n" +
            "carNo:车牌\n" +
            " \n" +
            "返回的内容id:id\n" +
            "companyId:公司id\n" +
            "carTeam:车队\n" +
            "phone:电话\n" +
            "name:姓名\n" +
            "idCard:身份证\n" +
            "carNo:车牌\n" +
            "whiteCard:白卡号\n" +
            "vehicleLicense:行驶证以及对应图片\n" +
            "driveLicense:驾驶证以及对应图片\n" +
            "corporationLicensePic:挂靠公司营业执照以及对应图片\n" +
            "bankName:银行名称\n" +
            "bankNo:银行卡卡号\n" +
            "state:审核状态: 已审核,未审核,审核未通过\n" +
            "orderNum:排序\n" +
            "createTime:创建时间\n" +
            "",httpMethod = "POST")
    @ResponseBody
    public JSONObject list(PageResult2<T> page, Driver driver, HttpServletRequest request)  throws Exception{
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "司机列表", "司机列表",
                request.getServletPath(), "POST", "ApiDriveController.list", request.getQueryString(),//JSONObject.toJSON(bill).toString(),
                "", getIpAddress(request)));
        return driverService.list(page, driver, getLoginUser(request));
    }

    /**
     * 添加司机
     */
    @PostMapping("/save")
    @ApiOperation(value = "平台手动添加司机",notes = "" +
            "username:帐号/手机号\n" +
            "name:姓名\n" +
            "idCard:身份证\n" +
            "phone:电话\n" +
            "carNo:车牌\n" +
            "whiteCard:白卡号\n" +
            "vehicleLicense:行驶证以及对应图片\n" +
            "driveLicense:驾驶证以及对应图片\n" +
            "corporationLicensePic:挂靠公司营业执照以及对应图片\n" +
            "bankName:银行名称\n" +
            "bankNo:银行卡卡号\n" +
            "",httpMethod = "POST")
    @ResponseBody
    public JsonResult save(Driver driver, User user, HttpServletRequest request) {
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "添加司机", "添加司机",
                request.getServletPath(), "POST", "ApiDriveController.save", request.getQueryString(),//JSONObject.toJSON(bill).toString(),
                "", getIpAddress(request)));
        return driverService.platsave(driver, user, getLoginUser(request));
    }


    /**
     * 司机修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "司机修改",notes = "" +
            "id 司机的id 必填\n" +
            //"name:司机姓名\n" +
            "phone:电话\n" +
            //"carNo:车牌\n" +
            //"idCard:身份证\n" +
            "whiteCard:白卡号\n" +
            "vehicleLicense:行驶证以及对应图片\n" +
            "driveLicense:驾驶证以及对应图片\n" +
            "corporationLicensePic:挂靠公司营业执照以及对应图片\n" +
            "bankName:银行名称\n" +
            "bankNo:银行卡卡号\n",httpMethod = "POST")
    @ResponseBody
    public JsonResult update(Driver driver, HttpServletRequest request) {
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "司机修改", "司机修改",
                request.getServletPath(), "POST", "ApiDriveController.update", request.getQueryString(),//JSONObject.toJSON(bill).toString(),
                "", getIpAddress(request)));
        return driverService.update(driver, getLoginUser(request));
    }

    /**
     * 司机对司机信息的修改
     */
    @PostMapping("/driverUpdate")
    @ApiOperation(value = "司机对司机信息修改",notes = "" +
            "id 司机的id 必填\n" +
            //"name:司机姓名\n" +
            "phone:电话\n" +
            //"carNo:车牌\n" +
            //"idCard:身份证\n" +
            "whiteCard:白卡号\n" +
            "vehicleLicense:行驶证以及对应图片\n" +
            "driveLicense:驾驶证以及对应图片\n" +
            "corporationLicensePic:挂靠公司营业执照以及对应图片\n" +
            "bankName:银行名称\n" +
            "bankNo:银行卡卡号\n" +
            "",httpMethod = "POST")
    @ResponseBody
    public JsonResult driverUpdate(Driver driver, HttpServletRequest request) {
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "司机对司机信息修改", "司机对司机信息修改",
                request.getServletPath(), "POST", "ApiDriveController.driverUpdate", request.getQueryString(),//JSONObject.toJSON(bill).toString(),
                "", getIpAddress(request)));
        return driverService.driverUpdate(driver, getLoginUser(request));
    }

    /**
     * 平台自己对司机信息的修改
     */
    @PostMapping("/platUpdate")
    @ApiOperation(value = "平台对司机信息修改",notes = "" +
            "id 司机的id 必填\n" +
            "name:司机姓名\n" +
            "phone:电话\n" +
            "carNo:车牌\n" +
            "idCard:身份证\n" +
            "whiteCard:白卡号\n" +
//            "vehicleLicense:行驶证以及对应图片\n" +
//            "driveLicense:驾驶证以及对应图片\n" +
//            "corporationLicensePic:挂靠公司营业执照以及对应图片\n" +
//            "bankName:银行名称\n" +
//            "bankNo:银行卡卡号\n" +
            "",httpMethod = "POST")
    @ResponseBody
    public JsonResult platUpdate(Driver driver, HttpServletRequest request) {
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "平台对司机信息修改", "平台对司机信息修改",
                request.getServletPath(), "POST", "ApiDriveController.platUpdate", request.getQueryString(),//JSONObject.toJSON(bill).toString(),
                "", getIpAddress(request)));
        return driverService.platUpdate(driver, getLoginUser(request));
    }


    @PostMapping("/examineSuccess")
    @ApiOperation(value = "司机审核通过",notes = "id driver表的id",httpMethod = "POST")
    @ResponseBody
    public JsonResult examineSuccess(Driver driver, HttpServletRequest request) {
        operRecordService.saveAsync(new OperRecord(Integer.valueOf(getLoginUserId(request)), "司机审核通过", "司机审核通过",
                request.getServletPath(), "POST", "ApiCustomerController.examineSuccess", request.getQueryString(),//JSONObject.toJSON(customer).toString(),
                "", getIpAddress(request)));

        return driverService.examine(driver, getLoginUser(request));
    }

}
